In [1]:
import json
import re
In [2]:
with open('../catalogs/json/gabi_2014.json') as fp:
G = json.load(fp)
In [3]:
G.viewkeys()
Out[3]:
In [4]:
## G['archives'] # this will generate thousands of lines of output and chokes the notebook.
## do this instead:
type(G['archives'])
Out[4]:
In [5]:
len(G['archives'])
Out[5]:
In [6]:
A = G['archives'][0]
type(A)
Out[6]:
In [7]:
A.keys()
Out[7]:
In [8]:
A['exchanges'][:10]
Out[8]:
In [9]:
te = [flow for flow in A['flows'] if re.search('Thermal', flow['tags']['Name'])]
In [10]:
te
Out[10]:
In [28]:
te[0]
Out[28]:
In [11]:
[q for q in A['quantities'] if q['dataSetReference'] == te[0]['ReferenceQuantity']]
Out[11]:
In [13]:
solar_processes = [p['process'] for p in A['exchanges'] if p['flow'] == te[2]['dataSetReference']]
In [14]:
solar_processes
Out[14]:
In [15]:
[p for p in A['processes'] if p['dataSetReference'] in solar_processes ]
Out[15]:
In [16]:
len([process for process in A['processes'] if process['ReferenceExchange'] == 'Output: %s' % te[0]['dataSetReference']])
Out[16]:
In [17]:
from collections import Counter
In [18]:
outflow = Counter()
for p in A['processes']:
outflow[p['ReferenceExchange']] +=1
In [19]:
outflow.most_common(50)
Out[19]:
In [20]:
def flow_from_exchange(ref):
return re.match('^(((In)|(Out))put: )?(.*)$', ref).groups()[-1]
In [21]:
def flow_name(ref):
return [f['tags']['Name'] for f in A['flows'] if f['dataSetReference'] == flow_from_exchange(ref)]
In [22]:
['%3d: %s' % (j, flow_name(i)) for i, j in outflow.most_common(5)]
Out[22]:
59 processes whose reference exchange is an input of Alumin[i]um scrap!!?
In [23]:
['%10s %s' %('[' + p['tags']['SpatialScope'] +']', p['tags']['Name']) for p in A['processes'] if p['ReferenceExchange'] == outflow.most_common(5)[4][0]]
Out[23]: